package login

import "C"
import (
	"github.com/gin-gonic/gin"
	"xy_api/app/models"
	"xy_api/pkg/api"
	"xy_api/pkg/jwt"
)

type User struct{}

func (*User) Login(c *gin.Context) {
	account, _ := c.GetPostForm("account")
	pwd, _ := c.GetPostForm("pwd")
	ojb, _ := models.AccountLogin(account)
	if ojb.Pwd == pwd { //pwd 需要加密哦
		token := jwt.NewJWT().IssueToken(ojb.ID, ojb.Name)
		api.Success(c, gin.H{
			"token": token,
		})
	} else {
		api.Fail(c, "账号或密码错误")
	}
}

func (*User) Info(c *gin.Context) {
	obj, _ := models.UserInfo(c.GetInt64("user_id"))
	api.Success(c, obj)
}
